package com.hyc.DataStructure.recursion;

/**
 * @projectName: DataStructure
 * @package: com.hyc.DataStructure.recursion
 * @className: recursionDemo
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2021/12/30 22:48
 * @version: 1.0
 */
public class recursionDemo {
    public static void main(String[] args) {
        //test(4);
        int factorial = factorial(6);
        System.out.println("res+=" + factorial);
    }

    //递归的初探 1. 输入一个数字 打印出来之前的数字 并且不小于二
    public static void test(int num) {
        if (num > 2) {
            test(num - 1);
        }
        System.out.println("res = " + num);
    }

    //   递归的初探， 输入数字，返回阶乘
    public static int factorial(int num) {
        if (num == 1) {
            return 1;
        } else {
            System.out.println(num);
            return factorial(num - 1) * num;
        }
    }
}
